﻿using Basic.WxGatewayModular.Interface;
using Basic.WxRemoteModel.WxBind;
using Basic.WxRemoteModel.WxBind.Model;

namespace Basic.WxGatewayModular.lmpl
{
    internal class MerBindService : IMerBindService
    {
        public string GetBindUri (string applyId, Uri localUri, bool isPc)
        {
            ApplyCodeResult code = new GetApplyBindCode
            {
                ApplyId = applyId
            }.Send();
            string uri = new Uri(localUri, "/wx/bind/callback/" + applyId).AbsoluteUri;
            if (isPc)
            {
                return string.Format("https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={0}&pre_auth_code={1}&redirect_uri={2}&auth_type={3}", code.ComponentAppId, code.PreAuthCode, uri, (int)code.AuthType);
            }
            return string.Format("https://open.weixin.qq.com/wxaopen/safe/bindcomponent?action=bindcomponent&no_scan=1&component_appid={0}&pre_auth_code={1}&redirect_uri={2}&auth_type={3}", code.ComponentAppId, code, uri, (int)code.AuthType);
        }
        public string GetCallback (string applyId)
        {
            return new GetBindCallback { ApplyId = applyId }.Send();
        }

    }
}
